﻿using System;
using System.Globalization;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace AccessControl.Sida.FingerPrintCollector.Login
{
	public partial class Login : XtraForm
	{
		public Login()
		{
			InitializeComponent();

		}

		private void BtnCencelClick(object sender, EventArgs e)
		{
			Application.Exit();
		}

		private void BtnLoginClick(object sender, EventArgs e)
		{
			TryLogin();
		}

		private void TryLogin()
		{
			if (LoginManager.Login(txtUsername.Text.Trim().ToLower(), txtPassword.Text.Trim()))
			{
				var cultureInfo = new CultureInfo("fa-IR");
				InputLanguage.CurrentInputLanguage = InputLanguage.FromCulture(cultureInfo);
				Hide();
			}
			else
			{
				XtraMessageBox.Show("نام کاربری یا رمز وارد شده اشتباه است", "سیستم تغذیه", MessageBoxButtons.OK, MessageBoxIcon.Error);
				txtUsername.Text = "";
				txtPassword.Text = "";
				txtUsername.Focus();
			}
		}

		private void FrmLoginKeyDown(object sender, KeyEventArgs e)
		{
			switch (e.KeyCode)
			{
				case Keys.Enter:
					TryLogin();
					break;

				case Keys.Escape:
					Application.Exit();
					break;
			}
		}
	}
}